package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IdCardSh;
import com.ruoyi.system.service.IIdCardShService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 身份证-所长Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@Controller
@RequestMapping("/system/cz_sh")
public class IdCardShController extends BaseController
{
    private String prefix = "system/cz_sh";

    @Autowired
    private IIdCardShService idCardShService;

    @RequiresPermissions("system:cz_sh:view")
    @GetMapping()
    public String cz_sh()
    {
        return prefix + "/cz_sh";
    }

    /**
     * 查询身份证-所长列表
     */
    @RequiresPermissions("system:cz_sh:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IdCardSh idCardSh)
    {
        startPage();
        List<IdCardSh> list = idCardShService.selectIdCardShList(idCardSh);
        return getDataTable(list);
    }

    /**
     * 导出身份证-所长列表
     */
    @RequiresPermissions("system:cz_sh:export")
    @Log(title = "身份证-所长", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IdCardSh idCardSh)
    {
        List<IdCardSh> list = idCardShService.selectIdCardShList(idCardSh);
        ExcelUtil<IdCardSh> util = new ExcelUtil<IdCardSh>(IdCardSh.class);
        return util.exportExcel(list, "身份证-所长数据");
    }

    /**
     * 新增身份证-所长
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存身份证-所长
     */
    @RequiresPermissions("system:cz_sh:add")
    @Log(title = "身份证-所长", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IdCardSh idCardSh)
    {
        return toAjax(idCardShService.insertIdCardSh(idCardSh));
    }

    /**
     * 修改身份证-所长
     */
    @RequiresPermissions("system:cz_sh:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IdCardSh idCardSh = idCardShService.selectIdCardShById(id);
        mmap.put("idCardSh", idCardSh);
        return prefix + "/edit";
    }

    /**
     * 修改保存身份证-所长
     */
    @RequiresPermissions("system:cz_sh:edit")
    @Log(title = "身份证-所长", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IdCardSh idCardSh)
    {
        return toAjax(idCardShService.updateIdCardSh(idCardSh));
    }

    /**
     * 删除身份证-所长
     */
    @RequiresPermissions("system:cz_sh:remove")
    @Log(title = "身份证-所长", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(idCardShService.deleteIdCardShByIds(ids));
    }
}
